#include <vector>

class Solution
{
public:
    static int minSubArrayLen(const int target, const std::vector<int>& nums)
    {
        int left = 0;
        int right =0;
        int len = 0;
        int sum = 0;

        while(right < nums.size())
        {
            sum += nums[right];
            while(sum >= target)
            {
                if(len==0)
                    len = right-left+1;
                else
                    len = std::min(len, right-left+1);
                sum -= nums[left];
                left++;
            }
            right++;
        }
        return len;
    }
};
